a=int(input())
if a > 9999 or a < 1000:
    print("0")
    exit()
num1=a //1000
num2=(a-num1*1000) // 100
num3=a//10 % 10
num4= a % 10
minN=0
b=[num1,num2,num3,num4,num1 * 10 + num2,num1 * 100 + num2*10 + num3,a,num2*10 + num3,num2 * 100 + num3*10 + num4,num3 * 10 + num4]
for i in range(len(b)):
    k = 0
    for j in range(2, b[i] // 2 + 1):
        if (b[i] % j == 0):
            k = k + 1
    if (k <= 0):
        if minN < b[i]:
            if b[i] != 1:
                minN = b[i]
print(minN)